package com.pfsoft.codehelper.controller;

import com.pfsoft.codehelper.domain.GenConfig;
import com.pfsoft.codehelper.common.response.BaseResponse;
import com.pfsoft.codehelper.service.GenConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Controller
public class GenConfigController {

    @Autowired
    private GenConfigService genConfigService;

    /**
     * 查询生成器配置
     * @return
     */
    @GetMapping(value = "/api/genConfig")
    public @ResponseBody ResponseEntity<BaseResponse<GenConfig>>  get(){
        BaseResponse<GenConfig> baseResponse=new BaseResponse<>();
        baseResponse.setData(genConfigService.find());
        baseResponse.setCode(200);
        baseResponse.setMessage("success");
        return new   ResponseEntity(baseResponse, HttpStatus.OK);
    }

    @PutMapping(value = "/api/genConfig")
    public ResponseEntity emailConfig(@Validated @RequestBody GenConfig genConfig){
        return new ResponseEntity(genConfigService.update(genConfig),HttpStatus.OK);
    }

    @GetMapping("/ctrl/config")
    public String getConfigIndex() {
        return "/ctrl/config";
    }

}
